package com.menghao.log.config;

import com.menghao.log.aop.LogAspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

/**
 * <p>Aop日志系统自配置类.<br>
 *
 * @author menghao.
 * @version 2017/11/30.
 */
@Configuration
@EnableConfigurationProperties(LogProperties.class)
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "menghao.log", value = "enable", matchIfMissing = false)
public class LogAutoConfiguration {

    private LogProperties logProperties;

    public LogAutoConfiguration(LogProperties logProperties) {
        Assert.notNull(logProperties.getFieldEnums(), "必须指定日志打印维度");
        this.logProperties = logProperties;
    }

    @Bean
    public LogAspect logAspect() {
        return new LogAspect(logProperties.getFieldEnums());
    }
}
